package com.icity.controller.content;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.icity.common.Result;
import com.icity.entity.content.BookToptenSupport;
import com.icity.entity.content.DrogonBookInfo;
import com.icity.entity.system.TableSupport;
import com.icity.service.ContentStatisticalService;
//内容统计
@RestController
@RequestMapping(value = "/admin/contentstatistical")
public class BookStatisticalController {
	@Autowired
	private ContentStatisticalService contentStatisticalService;

	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/booklist")
	@ResponseBody
	public Result getBook(HttpServletRequest request) {
		int page = Integer.parseInt(request.getParameter("page"));
		int limit = Integer.parseInt(request.getParameter("limit"));
		Map<Object,Object> map = new HashMap<Object,Object>();
		Result result = new Result();
		try {
			map.put("role_code", 1);
			map.put("page", (page-1)*limit);
			map.put("limit", limit);
			TableSupport<DrogonBookInfo> list = (TableSupport<DrogonBookInfo>) contentStatisticalService.getBookList(map);
			result.setCode("1");
			result.setMessage("获取成功");
			result.setData(list);
			return result;
		} catch (Exception e) {
			e.printStackTrace();
			result.setCode("-1");
			result.setMessage("获取数据异常");
			return result;
		}
	}

	@RequestMapping(value = "/book/lend/topten")
	@ResponseBody
	public Result getBookTopTenLend(HttpServletRequest request) {
		Result result = new Result();
		try {
			BookToptenSupport list = contentStatisticalService.getBookTopTenLend();
			result.setCode("1");
			result.setMessage("获取成功");
			result.setData(list);
			return result;
		} catch (Exception e) {
			e.printStackTrace();
			result.setCode("-1");
			result.setMessage("获取数据异常");
			return result;
		}
	}

	@RequestMapping(value = "/book/read/topten")
	@ResponseBody
	public Result getBookTopTenRead(HttpServletRequest request) {
		Result result = new Result();
		try {
			BookToptenSupport list = contentStatisticalService.getBookTopTenRead();
			result.setCode("1");
			result.setMessage("获取成功");
			result.setData(list);
			return result;
		} catch (Exception e) {
			e.printStackTrace();
			result.setCode("-1");
			result.setMessage("获取数据异常");
			return result;
		}
	}

}
